import request from '@/utils/request'
import { mockDashboardData } from './mock-data'

// 是否使用mock数据
const USE_MOCK = process.env.NODE_ENV === 'development'

// 获取仪表板概览数据
export function getOverview() {
  if (USE_MOCK) {
    return Promise.resolve(mockDashboardData.overview)
  }
  return request({
    url: '/dashboard/overview',
    method: 'get'
  })
}

// 获取销售趋势
export function getSalesTrend(days = 7) {
  if (USE_MOCK) {
    return Promise.resolve(mockDashboardData.salesTrend)
  }
  return request({
    url: '/dashboard/sales-trend',
    method: 'get',
    params: { days }
  })
}

// 获取销售构成
export function getSalesComposition() {
  if (USE_MOCK) {
    return Promise.resolve(mockDashboardData.salesComposition)
  }
  return request({
    url: '/dashboard/sales-composition',
    method: 'get'
  })
}

// 获取商品销售排行
export function getProductRank(limit = 10) {
  if (USE_MOCK) {
    return Promise.resolve(mockDashboardData.productRank)
  }
  return request({
    url: '/dashboard/product-rank',
    method: 'get',
    params: { limit }
  })
}

// 获取销售员业绩排行
export function getSalespersonRank(limit = 10) {
  if (USE_MOCK) {
    return Promise.resolve(mockDashboardData.salespersonRank)
  }
  return request({
    url: '/dashboard/salesperson-rank',
    method: 'get',
    params: { limit }
  })
}

// 获取日销售统计
export function getDailyStats(date) {
  return request({
    url: '/dashboard/daily-stats',
    method: 'get',
    params: { date }
  })
}

// 获取周销售统计
export function getWeeklyStats() {
  return request({
    url: '/dashboard/weekly-stats',
    method: 'get'
  })
}

// 获取月销售统计
export function getMonthlyStats() {
  return request({
    url: '/dashboard/monthly-stats',
    method: 'get'
  })
}

// 获取综合统计数据
export function getComprehensiveStats() {
  return request({
    url: '/dashboard/comprehensive-stats',
    method: 'get'
  })
}

// 获取销售曲线数据
export function getSalesCurve(period = 'month', interval = 'day') {
  return request({
    url: '/dashboard/sales-curve',
    method: 'get',
    params: { period, interval }
  })
}

// 获取热销商品排行
export function getTopProducts(period = 'month', limit = 20) {
  return request({
    url: '/dashboard/top-products',
    method: 'get',
    params: { period, limit }
  })
}

// 获取所有仪表板数据
export function getAllDashboardData() {
  return request({
    url: '/dashboard/all',
    method: 'get'
  })
}

// 获取销售概览数据
export function getSalesOverview(params) {
  return request({
    url: '/api/dashboard/sales-overview',
    method: 'get',
    params
  })
}

// 获取最近订单列表
export function getRecentOrders(params) {
  return request({
    url: '/api/dashboard/recent-orders',
    method: 'get',
    params
  })
}

// 获取客户增长数据
export function getCustomerGrowth(params) {
  return request({
    url: '/api/dashboard/customer-growth',
    method: 'get',
    params
  })
}

// 获取库存预警商品
export function getStockWarning() {
  return request({
    url: '/api/dashboard/stock-warning',
    method: 'get'
  })
} 

// 获取商品分类数据
export function getDashboardData() {
  return request({
    url: '/api/dashboard/dashboard-data',
    method: 'get'
  })
}